
var page = 0;
var pageShowCount = 10;
var searchName = "name";
var groupName = "studytypezh";
var groupText = "";
var classifyId = "";
var searchText = "";
var country = "";
var province = "";
var state = "";
var date = "";
function onfocusClear(id){
//	$("#"+id).val("");
}

/*******************************************************************************
 * 初始化
 */
$(document).ready(function(){
	$("#searchText").val(searchText);
	search();
	getProvinceList();
});

function changeCountry(countryid){
	country = countryid;
	if(""==countryid){
		$("#countryAll").addClass("seleA");
	}else{
		$("#countryAll").removeClass("seleA");
	}
	$("[name=countryA]").each(function(){
			$(this).removeClass("seleA");
			if(this.id=="country_"+countryid){
				$(this).addClass("seleA");
			}
	});
	search();
}

function changeState(stateStr){
	state = stateStr;
	search();
}

function changeDate(dateStr){
	date = dateStr;
	search();
}
function getProvinceList(){
	$.ajax({
   		async:false,
		url:'/ethicsCommittee_records/ethics-committee-records!getProvinceListo	.action',
		type:'POST',
		dataType:'json',
		cache: false,
		success:function(data){
			Interceptor(data);
			var types_='provice';
			var resultContent='';
			$(data).each(function(i) {
//				resultContent+='<option value="'+data[i].code+'">'+data[i].shortName+'</option>';
//				resultContent+='<li><a href="#">'+data[i].name+'</a></li>';
				
				var nameid=data[i].code;
				if(i<10){
					resultContent+='<li id="'+nameid+'_fltag"><a href="javascript:void(0);" onclick="selectFenbu(\''+data[i].code+'\')">'+data[i].name+'('+data[i].num+')</a></li>';
				}
				else{
					resultContent+='<li id="'+nameid+'_fltag" class="'+types_+'_fl" style="display:none;"><a href="javascript:void(0);" onclick="selectFenbu(\''+data[i].code+'\')">'+data[i].name+'('+data[i].num+')</a></li>';
				}
			});
			if(data.length>10){
				resultContent+='<li id="'+types_+'_more"><a href="javascript:void(0);" onclick="more(\''+types_+'\');">更多...</a></li>';
			}
			$("#proviceList").html(resultContent);
		}
	});
}
function more(types){
	$("."+types+"_fl").show();
	$("#"+types+"_more").html('<a href="javascript:void(0);" onclick="shouqi(\''+types+'\');">收起...</a>');
}

function shouqi(types){
	$("."+types+"_fl").hide();
	$("#"+types+"_more").html('<a href="javascript:void(0);" onclick="more(\''+types+'\');">更多...</a>');
}



function searchInstitution(item_id) {
	classifyId = item_id;
	getPageCount();
}

function selectFenbu(code){
	province=code;
	search();
}
 
/****
 * 回车判断
 * @param evt
 * @returns
 */
var SubmitOrHidden = function(evt){
    evt = window.event || evt;
    if(evt.keyCode==13){
    	search();
    	asAutoSuggest.clearSuggestions("fade");//AutoSuggest
     }
};
window.document.onkeydown=SubmitOrHidden;
/**************************************************
 * 自动提示
 */
function searchSuggest() {
	var baseUrl =basePath + "clinical-tral-registry!autosuggest.action";
	var options = {
		script : function() {
			return baseUrl+"?classifyID=clinicaltralregistry&keyWord="+encodeURI($("#searchText").val());
		},
		varname : "variableName",
		json : true,
		timeout : 3000,
		shownoresults : false,
		maxresults : 35,
		callback: function(record){
			//goselectts(record.id);//联动效果
		}
	};
	var as = new bsn.AutoSuggest('searchText', options);
}
/*******************************************************************************
 * 检索
 */
function search(){
	groupText = '';
	getPageCount();
}
/*******************************************************************************
 * 切换每页显示条数
 */
function changePageShowCount(changeId){
	var selectedVar = $("#"+changeId).find("option:selected");
	pageShowCount = selectedVar.text();
	var selectedIndex = $("#"+changeId).get(0).selectedIndex;
	$("[name=pageShowCount]").get(0).selectedIndex = selectedIndex;//
	$("[name=pageShowCount]").get(1).selectedIndex = selectedIndex;//
	search();
}
/*******************************************************************************
 * 查询记录总数
 */
function getPageCount(){
	searchText = $("#searchText").val();
	$.ajaxq("getPageCount", {
		async : false,
		url : '/ethicsCommittee_records/ethics-committee-records!getPageCount.action',
		type : 'post',
		dataType : 'json',
		data : {
			"searchText" : searchText,
			"country" :country,
			"state" :0
		},
		beforeSend : parent.msgLoading,
		complete : parent.successLoading,
		success : function(data) {
			Interceptor(data);
			$("[name=countTotal]").html(""+data);
			showPageResult(data);
		},
		error : function() {
			$("[name=countTotal]").html(""+data);
		}
	});
}
/*******************************************************************************
 * 分页
 */
function showPageResult(count) {
	if (count > 0) {
		$(".pagination").pagination(count, {
			num_edge_entries : 1, // 边缘页数
			num_display_entries : 10, // 主体页数
			prev_text : "上一页",
			next_text : "下一页",
			current_page : page,
			callback : showPageResultCallback,
			items_per_page : pageShowCount
		});
		$(".pagination").show();
	} else {
		$(".pagination").hide();
		var resultContent = '';
		resultContent +='<tr>'
						+'<th align="left" scope="col">机构名称</th>'
						+'<th align="left" scope="col">机构等级</th>'
						+'<th align="left" scope="col">所在省份</th>'
						+'<th align="left" scope="col">创建日期</th>'
						/*+'<th align="left" scope="col">审核状态</th>'*/
						+'<th align="left" scope="col">操作</th>'
					 +'</tr><tr><td colspan="6">暂无信息</td></tr>';
		$("#dataArea").html(resultContent);
	}
}

/*******************************************************************************
 * 返回数据集合
 */
function showPageResultCallback(page_index, jq) {
	$.ajaxq("getPageList", {
		async : false,
		url : '/ethicsCommittee_records/ethics-committee-records!getPageList.action',
		type : 'post',
		data : {
			"pageIndex" : page_index,
			"searchText" : searchText,
			"pageShowCount" : pageShowCount,
			"country" :country,
			"province" : province,
			"state" :0
		},
		dataType : 'json',
		beforeSend : parent.msgLoading,
		complete : parent.successLoading,
		success : function(data) {
			Interceptor(data);
			showSearchResultContent(data);
		},
		error : function() {
			alert("对不起，检索超时！");
		}
	});
	return false;
}

/*******************************************************************************
 * 显示数据集合
 */
function showSearchResultContent(data){
	var resultContent = '';
	resultContent +='<tr>'
					+'<th align="left" scope="col">机构名称</th>'
					+'<th align="left" scope="col">机构等级</th>'
					+'<th align="left" scope="col">所在省份</th>'
					+'<th align="left" scope="col">创建日期</th>'
					/*+'<th align="left" scope="col">审核状态</th>'*/
					+'<th align="left" scope="col">操作</th>'
				 +'</tr>';
	if(null!=data){
		$(data).each(function(i) {
			var dataObj = data[i];
			var id = dataObj.id;
	        var name = dataObj.name;
	        var organLevel = dataObj.organLevel;
	        var province = dataObj.province;
	        var status = dataObj.status;
	        var createdate = dataObj.createdate;
	        name = null==name?"":name;
	        organLevel = null==organLevel?"":organLevel;
	        province = null==province?"":province;
	        status = null==status?"":status;
	        createdate = null==createdate?"":createdate;
	        var detailUrl= basePath +"admin/ethicscommittee_records/ethicscommittee_records_auditdetails.jsp?id="+id;
	        var detailParticulars= basePath +"admin/organization_records/organization_records_detail.jsp?id="+id;
	        if(i%2==1){
	        	resultContent +='<tr>';
	        }else{
	        	resultContent +='<tr class="odd">';
	        }
    	    resultContent += '<td align="left"> &nbsp; <a href="'+detailParticulars+'" >'+name+'</a></td>'
							+'<td align="center">' + organLevel + '</td>'
							+'<td align="center">' + province + '</td>'
							+'<td align="center">'+createdate.substring(0,11)+'</td>'
							+ '<td align="center"><a href="'+detailUrl+'" >审核详情</a></td>'
						//	+'<td align="center">' + operaStr + '</td>'
						 +'</tr>';
	        
		});
		if(data==''){
			resultContent+='<tr><td colspan="6">暂无信息</td></tr>';
		}
	}else{
		resultContent+='<tr><td colspan="6">暂无信息</td></tr>';
	}
	$("#dataArea").html(resultContent);
}

function passOrg(jgid){
	if(confirm("您确定此机构通过审查?")){
		$.ajax({
			async:false,
			url:'/admin/org!saveOrgPass.action',
			type:'POST',
			data: {
				"id":jgid
			},
			dataType:'Text',
			cache: false,
			success:function(data){
				Interceptor(data);
				if(data!=null){
					alert("操作成功");
					location.href = '/admin/organization_records/organization_records_audit.jsp';
				}
			},
			error:function(){
				//nexts(tag);
			}
		});
	}
}

/*******************************************************************************
 * 分组查询条目
 */
function searchGroupBy(item){
	groupText = item;
	getPageCount();
}
